package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.AccountInfoRespond;
import com.jiutong.meipengdai.entity.AddressBean;
import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.entity.LoanOprRecordRespond;
import com.jiutong.meipengdai.entity.LoanRecordRespond;
import com.jiutong.meipengdai.entity.MsgCenterRespond;
import com.jiutong.meipengdai.entity.MsgDetailRespond;
import com.jiutong.meipengdai.entity.ReplayRecoreRespond;
import com.jiutong.meipengdai.entity.ScoreRespond;
import com.jiutong.meipengdai.http.model.interfaces.MyAccountBiz;
import com.jiutong.meipengdai.http.model.requests.MyAccountRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * Created by suxi on 2017/6/1.
 */

public class MyAccountPresent {


    private final Context mContext;
    private final MyAccountBiz mBaseBiz;
    private final MyAccountRequest mapRequest;

    public MyAccountPresent(Context context, MyAccountBiz biz) {
        this.mContext = context;
        this.mBaseBiz = biz;
        mapRequest = new MyAccountRequest();
    }

    /**
     * 获取账户信息
     */
    public void getAccountInfo() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<AccountInfoRespond>() {
            @Override
            public void onNext(AccountInfoRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getAccountInfo(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 获取账户信息
     */
    public void getAccountSetting() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<AccountInfoRespond>() {
            @Override
            public void onNext(AccountInfoRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getAccountSetting(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }


    /**
     * 消息中心
     */
    public void getMsgCenter() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<MsgCenterRespond>() {
            @Override
            public void onNext(MsgCenterRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getMsgCenter(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 消息中心
     */
    public void getMsgDetail() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<MsgDetailRespond>() {
            @Override
            public void onNext(MsgDetailRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("msgId", mBaseBiz.getMsgId());
        mapRequest.getMsgDetail(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 还款记录
     */
    public void getRepayRecord() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<ReplayRecoreRespond>() {
            @Override
            public void onNext(ReplayRecoreRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getRepayRecord(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 贷款记录
     */
    public void getLoanRecord() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<LoanRecordRespond>() {
            @Override
            public void onNext(LoanRecordRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getLoanRecord(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 贷款操作记录
     */
    public void getLoanoprRecord() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<LoanOprRecordRespond>() {
            @Override
            public void onNext(LoanOprRecordRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("loanId", mBaseBiz.getLoanId());
        mapRequest.getLoanoprRecord(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 我的积分
     */
    public void getScore() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<ScoreRespond>() {
            @Override
            public void onNext(ScoreRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getScore(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 获取地址列表
     */

    public void getAddressList() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<AddressBean>() {
            @Override
            public void onNext(AddressBean subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };
        HashMap<String, Object> fieldsMap = new HashMap<>();
        mapRequest.getAddress(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }


    /**
     * 修改地址和删除地址 同一接口
     */
    public void saveAddress() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
            @Override
            public void onNext(BaseRespond o) {
                mBaseBiz.onSuccess(o);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };
        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("recipients", mBaseBiz.Consignee());
        fieldsMap.put("telephone", mBaseBiz.getTelephone());
        fieldsMap.put("location", mBaseBiz.getBigLocation());
        fieldsMap.put("detail", mBaseBiz.getDetail());
        fieldsMap.put("prior", mBaseBiz.getIsDefault());
        fieldsMap.put("addId", mBaseBiz.getMainId());
        fieldsMap.put("oprType", mBaseBiz.getOprType());

        mapRequest.saveAddress(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 新建收货地址
     */

    public void saveNewAddress() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
            @Override
            public void onNext(BaseRespond o) {
                mBaseBiz.onSuccess(o);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };
        HashMap<String,Object> fieldsMap=new HashMap<>();
        fieldsMap.put("recipients", mBaseBiz.Consignee());
        fieldsMap.put("telephone", mBaseBiz.getTelephone());
        fieldsMap.put("location", mBaseBiz.getBigLocation());
        fieldsMap.put("detail", mBaseBiz.getDetail());
        fieldsMap.put("prior", mBaseBiz.getIsDefault());
        mapRequest.saveNewAddress(new ProgressSubscriber(onNextListener,mContext),fieldsMap);
    }



}
